<template>
  <div>
    <div
      class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
    >
      <div class="mui-scroll">
        <a
          :class="['mui-control-item',item.id===0?'mui-active':'']"
          v-for="item in category"
          :key="item.id"
          @click="getPhotoById(item.id)"
        >{{ item.title }}</a>
      </div>
    </div>
    <ul style="list-style:none" class="photo-list">
      <router-link v-for="item in list" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <div class="info_title">{{ item.title }}</div>
          <div class="info_body">{{ item.zhaiyao }}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.js";
export default {
  created() {
    this.getCategory();
    this.getPhotoById(0);
  },
  //组件（dom）加载成功后执行
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  data() {
    return {
      category: [],
      list: []
    };
  },
  methods: {
    getCategory() {
      this.$http.get("api/getimgcategory").then(data => {
        console.log(data.body);
        data.body.message.unshift({ title: "全部", id: 0 });
        this.category = data.body.message;
      });
    },
    getPhotoById(id) {
      this.$http.get("api/getimages/" + id).then(data => {
        console.log(data.body);
        this.list = data.body.message;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
img[lazy="loading"] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.photo-list {
  margin: 0;
  padding: 10px;
  li {
    text-align: center;
    box-shadow: 0 0 9px #999;
    position: relative;
    margin-bottom: 10px;
    img {
      width: 100%;
      vertical-align: middle;
    }
    .info {
      position: absolute;
      left: 0px;
      bottom: 0px;
      background-color: rgba(0, 0, 0, 0.4);
      color: white;
      text-align: left;
      max-height: 84px;
      .info_title {
        font-size: 14px;
      }
      .info_body {
        font-size: 13px;
      }
    }
  }
}
</style>
